#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include<iostream>
#include<string.h>

using namespace std;

namespace WX
{
	class string
	{
	public:
		//string()
		//	:_str(new char[1]{'\0'})
		//	,_capacity(0)
		//	,_size(0)
		//{}

		//string(const char* str)
		//	:_size(strlen(str))
		//{
		//	_capacity = _size;
		//	_str = new char[_size + 1];
		//	strcpy(_str, str);
		//}

		string(const char* str = "");

		//string(const string& str);

		char* c_str()
		{
			return _str;
		}
		void reserve(size_t n)
		{
			if (n > _capacity)
			{
				char* tmp = new char[n + 1];
				strcpy(tmp, _str);
				delete[] _str;
				_str = tmp;
			}
		}

		void push_back(char ch)
		{
			if (_size + 1 > _capacity)
			{
				reserve(_capacity == 0 : 4 ? _capacity * 2);
			}
			_str[_size] = ch;
			_size++;
			_str[_size] = '\0';
		}

		void append(char* str)
		{
			size_t len = strlen(str);
			if (_size + len > _capacity)
			{
				size_t newCapacity = _capacity * 2;
				if (_size + len > newCapacity)
				{
					newCapacity = _size + len;
				}
				reserve(newCapacity);
			}
			_size += len;
		}


		~string();

	private:
		char* _str;
		int _capacity;
		int _size;
	};
}


void test5();